package Operation;

import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        System.out.println("借阅图书");

        int choic = 1;
        Scanner scanner = new Scanner(System.in);
        while (choic == 1) {
            System.out.println("立刻查找图书");
            System.out.println("请输入你要借阅书的名字》");
            String name = scanner.next();
            int tail = 0;
            int i = 0;
            for (i = 0; i < booklist.getUsedSize(); i++) {
                if (name.equals(booklist.getName(i))) {
                    tail = i;
                    break;
                }
            }
            if (i == booklist.getUsedSize()) {
                System.out.println("找不到这本书，无法借阅！");
            } else {
                if (booklist.getBook(tail).getIsBorrowed() == true) {
                    booklist.getBook(tail).setBorrowed();
                    System.out.println("借阅成功！");

                } else {
                    System.out.println("抱歉，书架上有这本书但是被借走了。");
                }
            }
            System.out.println("是否继续添加》  1》继续   0》停止  输入其他数字》停止");
            choic = scanner.nextInt();
        }
    }
}
